/**
 * Created by wenchuan on 2018/5/4.
 */
define(function () {

    var self,
        app = win.app,
        others = {
            ischecked: '0'
        },
        pageParameters,
        order
    ;

    var OrderTemp = app.Module.extend({

        init: function () {
            self = this;
            pageParameters = app.pageParameters['zpordertemp_page'];
            order = pageParameters.items;
            self._super({}, win);
        },
        subData: function (_p1) {
            app.openPage({
                src: "yxsjzp/order-submit.html",
                argsKey: 'zpordersubmit_page',
                args: {
                    order: order,
                    items: [_p1],
                    cb: function () {
                        pageParameters.cb();
                    }
                }
            });
        },
        deleteItem:function (val) {
            app.ajax({
                xurl: "api/wx/gwat200/wzpDelete",
                loading: true,
                errmsg: '删除操作异常',
                xdata: {
                    GWCMDOCNO: order.GWCMDOCNO,
                    GWCMSEQ:val.GWCMSEQ
                },
                confirm:{
                    msg:'确定删除此商品？'
                },
                cb: function (result) {
                    if (result.ok) {
                        //app.toast('删除成功');
                        order.details.remove(val);
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            new Vue({
                el: app.getByid(doc, 'scroll1'),
                data: {
                    items: order.details.addMap({
                        ischecked: '1'
                    }, true)
                },
                methods: {}
            });
            new Vue({
                el: app.getByid(doc, 'contentFooter'),
                data: others,
                methods: {
                    subOrder: function () {
                        var _p1 = app.cloneJSON(order);
                        _p1.details.pushArray(order.details.filterKV({
                            ischecked: '1'
                        }), true);

                        if (_p1.details.length > 0) {
                            app.confirm({
                                msg: '确定是否提交？',
                                ok: function (e) {
                                    self.subData(_p1);
                                }
                            });
                        }
                    },
                    addOrder: function () {
                        var _orderInfo = app.cloneJSON(order);
                        delete _orderInfo.details;
                        app.openPage({
                            src: "yxsjzp/zp-add-classes.html",
                            argsKey: 'classes_page',
                            args: {
                                type: 'paidan',
                                orderInfo: _orderInfo,
                                cb: function (order_) {
                                    order.details.push(order_);
                                    app.back(2);
                                }
                            }
                        });
                    },
                    checkChange: function () {
                        self._getRefreshObj().data.addMap({
                            ischecked: others.ischecked
                        }, true);
                    }
                }
            });
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        },
        _ready: function () {
            Vue.component('ordertemp-listitem', {
                template: app.getByid(doc, 'cartitem-template'),
                props: {
                    model: Array
                },
                methods: {
                    minus: function (val) {
                        if (val.GWCM003 > 1) {
                            val.GWCM003--;
                        }
                    },
                    plus: function (val) {
                        val.GWCM003++;
                    },
                    showDetail:function (item) {
                        item.GWCMDOCNO = order.GWCMDOCNO;
                        app.openPage({
                            src: "yxsjzp/zp-classes-info.html",
                            argsKey: 'zpclassesinfo_page',
                            args: {
                                order: item,
                                cb: function (order) {
                                    app.back(1);
                                }
                            }
                        });
                    },
                    deleteItem:function (item,elobj) {
                        self.deleteItem(item);
                        mui.swipeoutClose($(elobj.target).parents("li").get(0));
                    }
                }
            });
        }
    });

    return new OrderTemp();

});